package com.agent.membership.exception;

import com.agent.common.result.ApiResponse;
import com.agent.common.result.ResultCode;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 * @author Jeff_Wan
 * @description 处理控制器层的异常
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(CreditException.class)
    public ApiResponse<?> handleCreditException(CreditException ex) {
        return ApiResponse.fail(ex.getResultCode(), ex.getMessage());
    }

    @ExceptionHandler(com.agent.common.exception.BusinessException.class)
    public ApiResponse<?> handleBusinessException(com.agent.common.exception.BusinessException ex) {
        return ApiResponse.fail(ex.getResultCode(), ex.getMessage());
    }

    @ExceptionHandler(Exception.class)
    public ApiResponse<?> handleException(Exception ex) {
        return ApiResponse.fail(ResultCode.INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}